<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
</head>
<body>

<div id="app">
    <h2>全书总价格：{{totalPrice}}元</h2>

</div>

<script src="../js/vue.js"></script>
<script>
    const app = new Vue
    (
        {
            el : "#app",
            data : 
            {
                message : "hello",
                
                books : 
                [
                    {id : 110, name : 'Unix编程艺术', price : 119},
                    {id : 111, name : 'Unix编程艺术', price : 105},
                    {id : 112, name : 'Unix编程艺术', price : 98},
                    {id : 113, name : 'Unix编程艺术', price : 87},
                ]
            },

            computed : 
            {
                totalPrice : function ()
                {
                    let result = 0;
                    // 方法一：
                    // for (let i = 0; i < this.books.length; i++)
                    // {
                    //     result += this.books[i].price;
                    // }
                    // return result;

                    // 方法二：
                    for (let books of this.books)
                    {
                        result += books.price;
                    }
                    return result;

                    // 方法三：
                    
                }    
            }
        }
    )
</script>
    
</body>
</html>